/**
 * Copyright 2011 Joe Choi, All rights reserved.
 */
package tec.fs;

import java.io.File;

import tao.data.structure.Iterator;
import tao.data.structure.List;
import tao.data.structure.tree.Tree;
import tao.data.structure.tree.Trees;
import tec.data.structure.ConcreteList;

/**
 * The tree data structure for holding the File objects
 * 
 * <br><br>
 * For speed up the creation of file tree, just partial tree will be built. The 
 * non-built node will be built once it is traversed 
 * 
 * @author Joe Choi
 */
public class FileTree implements Tree<File> {
	public FileTree(File root) {
		subtree = new FileTrees(root.listFiles());
	}

	@Override
	public Trees<FileTree> getSubtree() {
		return(subtree);
	}
		
	@Override
	public File getValue() {
		return(node);
	}

	@Override
	public int degree() {
		return(subtree.size());
	}

	private File node;
	private FileTrees subtree;
		
	private static class FileTrees implements Trees<FileTree> {
		public FileTrees(File[] files) {
			nodes = new ConcreteList<FileTree>();
			
		}
		
		@Override
		public int size() {
			return(nodes.size());
		}
		
		@Override
		public Iterator<FileTree> iterator() {
			return(nodes.iterate());
		}
		
		private List<FileTree> nodes;
	}
}